﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Input_SaleProcessIndefinForm
 * 类型：       控制层
 * 功能说明：   销售过程-资格审核页面
 * 作者：       章 昕
 * 创建日期：   2007/08/30
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Input.Dao;
using Shpm.App.Input.Bean;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.App.Commons.Db.Beans.Inp;
using Shpm.App.Commons.Utils;
using Shpm.System.Web.Control;
using log4net;
using System.Text.RegularExpressions;
using Shpm.System;
using Shpm.App.Master.Dao;
using Shpm.App.Master.Bean;

public partial class App_Input_SaleProcessIndefinForm : System.Web.UI.Page
{
    // log
    protected static ILog log = LogManager.GetLogger(typeof(App_Input_SaleProcessIndefinForm));

    // page load
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!Page.IsPostBack)
            {
                // 流ID
                this.ViewState["PROC_ID"] = "";
                // 流取消Flg
                this.ViewState["CANCEL_FLG"] = null;
                // 流当前步序
                //this.ViewState["CUR_STEP"] = null;

                if (Context.Items["SALE_PROC_ID"] != null)
                {
                    this.ViewState["PROC_ID"] = Convert.ToString(Context.Items["SALE_PROC_ID"]);
                }
              

                if (Context.Items["PERSON_ID"] != null)
                {
                    this.ViewState["PERSON_ID"] = Convert.ToString(Context.Items["PERSON_ID"]);
                }
                if (Context.Items["MAIN_PERSON_ID"] != null)
                {
                    this.ViewState["MAIN_PERSON_ID"] = Convert.ToString(Context.Items["MAIN_PERSON_ID"]);
                }


                
                // load exist data
                Boolean blnFindData = false;
                if (this.ViewState["PROC_ID"].ToString().Length > 0)
                {
                    blnFindData = bindSelectData(this.ViewState["PROC_ID"].ToString());
                }

                // has auth 审核权限 check waiting  To change       
                SysUserManager manager = new SysUserManager(Context);
                SysUserBean sysUserBean = manager.getSysUserBean();
                MstSysUserBean mstSysUserBean =
                    sysUserBean == null ? null : sysUserBean.getMstSysUserBean();
                MstEmployeeBean mstEmpBean =
                    sysUserBean == null ? null : sysUserBean.getEmployeeBean();
                string loginId = mstSysUserBean == null ? "" : mstSysUserBean.SysUserId;
                string emplyId = mstSysUserBean == null ? "" : mstSysUserBean.EmployeeId;
                string emplyRole = mstEmpBean == null ? "" : mstEmpBean.Role;
                if (!SaleProcessDao.ROLE_MANAGER.Equals(emplyRole))
                {
                    ((Design_MasterPage)this.Master).InfoMessage =
                        HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0901").ToString();
                    btnOk.Enabled = false;
                }
                lblCurUser.Text = String.IsNullOrEmpty(lblCurUser.Text) ? emplyId : lblCurUser.Text;

                SaleProcessDao dao = new SaleProcessDao();
                SaleProcessBean beanSP = new SaleProcessBean();

                beanSP.SaleProcId = Convert.ToInt32(this.ViewState["PROC_ID"]);
                beanSP = dao.FindBySaleProcess(beanSP);
                if (beanSP.PersonId == null)
                {
                    ((Design_MasterPage)this.Master).InfoMessage =
                        HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0005").ToString();
                    btnSave.Enabled = false;
                    memberRadio.Items[0].Enabled = false;
                    return;
                }
                if (string.IsNullOrEmpty(Convert.ToString(this.ViewState["PERSON_ID"])))
                {
                    this.ViewState["PERSON_ID"] = Convert.ToString(beanSP.PersonId);
                    
                }
                if (string.IsNullOrEmpty(Convert.ToString(this.ViewState["MAIN_PERSON_ID"])))
                {
                    this.ViewState["MAIN_PERSON_ID"] = Convert.ToString(beanSP.PersonId);
                }

                
            }
        }
        catch (Exception ex)
        {
            log.Fatal(ex.StackTrace);
            log.Fatal(ex.Message);
            throw ex;
        }
        SetControls();
        
    }

    /*名称： setInteControls
     *功能： 加载默认数据
     *参数： 无
     *返回： 无
     *说明： 无
     */
    private void setInteControls()
    {
        EmployeeDao employeeDao = new EmployeeDao();
        EmployeeBean employeeBean = new EmployeeBean();
        IList authorityList = new ArrayList();

        for (int i = 0; i + 1 < TblSale.Rows.Count; i++)
        {
            HiddenField hidDepartId = (HiddenField)TblSale.Rows[1 + i].Cells[1].FindControl(string.Format("hidDepartId_{0}", i));
            DropDownList d = (DropDownList)TblSale.Rows[1 + i].Cells[2].FindControl(string.Format("dropDownList_Auditing_{0}", i));
            employeeBean.DepartId = hidDepartId.Value; 
            authorityList = employeeDao.FindDepartmentEmp(employeeBean);
            authorityList.Insert(0, new EmployeeBean());
            d.DataSource = authorityList;
            d.DataBind();
        }

        SaleProcessDao dao = new SaleProcessDao();
        SaleProcessBean beanSP = new SaleProcessBean();

        beanSP.SaleProcId = Convert.ToInt32(this.ViewState["PROC_ID"]);
        beanSP = dao.FindBySaleProcess(beanSP);
        if (beanSP.SecondaryPersonId == null)
        {
            memberRadio.Items[1].Enabled = false;
        }
        if (beanSP.AccompanyPersonId == null)
        {
            memberRadio.Items[2].Enabled = false;
        }

        SaleProcessIndefinBean bean = new SaleProcessIndefinBean();
        SaleProcessIndefinDao daoSP = new SaleProcessIndefinDao();
        bean.PersonId = Convert.ToInt32(this.ViewState["PERSON_ID"]);
        IList list = daoSP.GetListSaleProcessIndefin(bean);
        if (list.Count != 0)
        {
            for (int i = 0; i + 1 < TblSale.Rows.Count; i++)
            {
                SaleProcessIndefinBean dataBean = new SaleProcessIndefinBean();
                DropDownList d = (DropDownList)TblSale.Rows[1 + i].Cells[2].FindControl(string.Format("dropDownList_Auditing_{0}", i));
                TextBox t = (TextBox)TblSale.Rows[1 + i].Cells[4].FindControl(string.Format("txtMemo_{0}", i));
                dataBean = (SaleProcessIndefinBean)list[i];
                d.SelectedValue = dataBean.AuditingId;
                t.Text = dataBean.AuditingMemo;
            }
        }

    }


    /*名称： SetControls
     *功能： 加载画面
     *参数： 无
     *返回： 无
     *说明： 无
     */
    protected void SetControls()
    {
        SaleProcessIndefinBean bean = new SaleProcessIndefinBean();
        SaleProcessIndefinDao dao = new SaleProcessIndefinDao();
        CommonDictionaryDao dicDao = new CommonDictionaryDao();
        CommonDictionaryBean dicBean = new CommonDictionaryBean();
        int k = 0;
        bean.PersonId = Convert.ToInt32(this.ViewState["PERSON_ID"]);
        IList list = dao.GetListSaleProcessIndefin(bean);
        IEnumerator enm;
        if (list.Count == 0)
        {
            CommonDictionaryBean dataBean;
            dicBean.Catalog = "T_SALES_PROC_AUDITING.DEPART_ID";
            list = dicDao.FindByCatalog(dicBean);
            enm = list.GetEnumerator();
            while (enm.MoveNext())
            {
                dataBean = (CommonDictionaryBean)enm.Current;
                TableRow tblRow = new TableRow();
                // 编号
                TableCell tblCell;
                tblCell = new TableCell();
                tblCell.HorizontalAlign = HorizontalAlign.Center;
                tblCell.Controls.Add(new LiteralControl(Convert.ToString(k + 1)));
                tblRow.Cells.Add(tblCell);

                // 部门
                tblCell = new TableCell();
                tblCell.HorizontalAlign = HorizontalAlign.Center;
                tblCell.Controls.Add(new LiteralControl(Convert.ToString(dataBean.Content)));

                HiddenField hidDepartId = new HiddenField();
                hidDepartId.ID = string.Format("hidDepartId_{0}", k);
                hidDepartId.Value = dataBean.DictNo;
                tblCell.Controls.Add(hidDepartId);
                tblRow.Cells.Add(tblCell);

                // 审核人
                tblCell = new TableCell();
                tblCell.HorizontalAlign = HorizontalAlign.Center;
                DropDownList d = new DropDownList();
                d.ID = string.Format("dropDownList_Auditing_{0}", k);
                d.DataTextField = "EmployeeName";
                d.DataValueField = "EmployeeId";
                d.Width=75;
                tblCell.Controls.Add(d);
                tblRow.Cells.Add(tblCell);

                // 是否选择
                tblCell = new TableCell();
                tblCell.HorizontalAlign = HorizontalAlign.Center;
                CheckBox c = new CheckBox();
                c.ID = string.Format("checkBox_Flg_{0}", k);
                tblCell.Controls.Add(c);
                tblRow.Cells.Add(tblCell);


                // 备注
                tblCell = new TableCell();
                tblCell.HorizontalAlign = HorizontalAlign.Center;
                TextBox txtMemo = new TextBox();
                txtMemo.ID = string.Format("txtMemo_{0}", k);
                txtMemo.Width = 300;
                txtMemo.Height = 30;
                txtMemo.TextMode = TextBoxMode.MultiLine;
                tblCell.Controls.Add(txtMemo);
                tblRow.Cells.Add(tblCell);

                TblSale.Rows.Add(tblRow);
                k = k + 1;

            }

        }
        else
        {
            SaleProcessIndefinBean dataBean;
            enm = list.GetEnumerator();
            while (enm.MoveNext())
            {
                dataBean = (SaleProcessIndefinBean)enm.Current;
                TableRow tblRow = new TableRow();

                // 编号
                TableCell tblCell;
                tblCell = new TableCell();
                tblCell.HorizontalAlign = HorizontalAlign.Center;
                tblCell.Controls.Add(new LiteralControl(Convert.ToString(k + 1)));

                HiddenField hidRowId = new HiddenField();
                hidRowId.ID = string.Format("hidRowId_{0}", k);
                hidRowId.Value =Convert.ToString(dataBean.RowId);
                tblCell.Controls.Add(hidRowId);
                tblRow.Cells.Add(tblCell);

                // 部门
                tblCell = new TableCell();
                tblCell.HorizontalAlign = HorizontalAlign.Center;
                tblCell.Controls.Add(new LiteralControl(dataBean.DepartName));

                
                HiddenField hidDepartId = new HiddenField();
                hidDepartId.ID = string.Format("hidDepartId_{0}", k);
                hidDepartId.Value =Convert.ToString(dataBean.DepartId);
                tblCell.Controls.Add(hidDepartId);
                tblRow.Cells.Add(tblCell);

                // 审核人
                tblCell = new TableCell();
                tblCell.HorizontalAlign = HorizontalAlign.Center;
                DropDownList d = new DropDownList();
                d.ID = string.Format("dropDownList_Auditing_{0}", k);
                //d.SelectedValue = Convert.ToString(dataBean.AuditingId);
                d.DataTextField = "EmployeeName";
                d.DataValueField = "EmployeeId";
                d.Width = 75;
                tblCell.Controls.Add(d);
                tblRow.Cells.Add(tblCell);

                // 是否选择
                tblCell = new TableCell();
                tblCell.HorizontalAlign = HorizontalAlign.Center;
                CheckBox c = new CheckBox();
                c.ID = string.Format("checkBox_Flg_{0}", k);
                
                if (dataBean.AuditingFlg == 1)
                {
                    c.Checked = true;
                }
                else
                {
                    c.Checked = false;
                }
                tblCell.Controls.Add(c);
                tblRow.Cells.Add(tblCell);


                // 备注
                tblCell = new TableCell();
                tblCell.HorizontalAlign = HorizontalAlign.Center;
                TextBox txtMemo = new TextBox();
                txtMemo.ID = string.Format("txtMemo_{0}", k);
                txtMemo.Text = dataBean.AuditingMemo;
                txtMemo.Width = 300;
                txtMemo.Height = 30;
                txtMemo.TextMode= TextBoxMode.MultiLine;     
                tblCell.Controls.Add(txtMemo);
                tblRow.Cells.Add(tblCell);

                TblSale.Rows.Add(tblRow);
                k = k + 1;
            }
        }

    }

    // before render
    void Page_PreRender(object sender, EventArgs e)
    {
        setInteControls();
       
        // 销售过程跟踪 link 状态
        //setLinkStatus();
        SaleProcessDao dao = new SaleProcessDao();
        SaleProcessBean beanSP = new SaleProcessBean();

        beanSP.SaleProcId = Convert.ToInt32(this.ViewState["PROC_ID"]);
        beanSP = dao.FindBySaleProcess(beanSP);
        if (beanSP.PersonId == Convert.ToInt32(this.ViewState["PERSON_ID"]))
        {
            memberRadio.Items[0].Selected = true;
        }
        else if (beanSP.SecondaryPersonId == Convert.ToInt32(this.ViewState["PERSON_ID"]))
        {
            memberRadio.Items[1].Selected = true;
        }
        else if (beanSP.AccompanyPersonId == Convert.ToInt32(this.ViewState["PERSON_ID"]))
        {
            memberRadio.Items[2].Selected = true;
        }

        labelName.Text = beanSP.PersonNameMain;
        if (!string.IsNullOrEmpty(beanSP.PersonNameAsst))
        {
            labelSecondaryName.Text = beanSP.PersonNameAsst;
        }
        else
        {
            labelSecondaryName.Text = "---";
        }

        if (!string.IsNullOrEmpty(beanSP.PersonNameComp))
        {
            labelAccompanyName.Text = beanSP.PersonNameComp;
        }
        else
        {
            labelAccompanyName.Text = "---";
        }

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        SaleProcessIndefinBean bean = new SaleProcessIndefinBean();
        SaleProcessIndefinDao dao = new SaleProcessIndefinDao();
        bean.PersonId = Convert.ToInt32(this.ViewState["PERSON_ID"]);
        IList ilist = dao.GetListSaleProcessIndefin(bean);
        IList list = new ArrayList();
        string strFlg;
        if (ilist.Count == 0)
        {
            for (int i = 0; i + 1 < TblSale.Rows.Count; i++)
            {
                SaleProcessIndefinBean dataDean = new SaleProcessIndefinBean();
                HiddenField hidDepartId = (HiddenField)TblSale.Rows[1 + i].Cells[1].FindControl(string.Format("hidDepartId_{0}", i));
                DropDownList d = (DropDownList)TblSale.Rows[1 + i].Cells[2].FindControl(string.Format("dropDownList_Auditing_{0}", i));
                CheckBox c = (CheckBox)TblSale.Rows[1 + i].Cells[3].FindControl(string.Format("checkBox_Flg_{0}", i));
                TextBox t = (TextBox)TblSale.Rows[1 + i].Cells[4].FindControl(string.Format("txtMemo_{0}", i));
                dataDean.SaleProcId = Convert.ToInt32(this.ViewState["PROC_ID"]);
                dataDean.PersonId = Convert.ToInt32(this.ViewState["PERSON_ID"]);
                dataDean.DepartId = Convert.ToInt32(hidDepartId.Value);
                dataDean.AuditingId = d.SelectedValue;
                dataDean.AuditingMemo = t.Text;
                if (c.Checked == true)
                {
                    dataDean.AuditingFlg = 1;
                    if (string.IsNullOrEmpty(dataDean.AuditingId))
                    {
                        ((Design_MasterPage)this.Master).InfoMessage =
                            HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0100").ToString().Replace("{0}", "审核人");
                        return;
                    }
                }
                else
                {
                    dataDean.AuditingFlg = 0;
                    dataDean.AuditingId = "";
                    dataDean.AuditingMemo="";
                }
                
                list.Add(dataDean);
            }
            strFlg = "0";

        }
        else
        {
            for (int i = 0; i + 1 < TblSale.Rows.Count; i++)
            {
                SaleProcessIndefinBean dataDean = new SaleProcessIndefinBean();

                HiddenField hidRowId = (HiddenField)TblSale.Rows[1 + i].Cells[0].FindControl(string.Format("hidRowId_{0}", i));
                HiddenField hidDepartId = (HiddenField)TblSale.Rows[1 + i].Cells[1].FindControl(string.Format("hidDepartId_{0}", i));
                DropDownList d = (DropDownList)TblSale.Rows[1 + i].Cells[2].FindControl(string.Format("dropDownList_Auditing_{0}", i));
                CheckBox c = (CheckBox)TblSale.Rows[1 + i].Cells[3].FindControl(string.Format("checkBox_Flg_{0}", i));
                TextBox t = (TextBox)TblSale.Rows[1 + i].Cells[4].FindControl(string.Format("txtMemo_{0}", i));
                dataDean.RowId = Convert.ToInt32(hidRowId.Value);
                dataDean.SaleProcId = Convert.ToInt32(this.ViewState["PROC_ID"]);
                dataDean.PersonId = Convert.ToInt32(this.ViewState["PERSON_ID"]);
                dataDean.DepartId = Convert.ToInt32(hidDepartId.Value);
                dataDean.AuditingId = d.SelectedValue;
                dataDean.AuditingMemo = t.Text;
                if (c.Checked == true)
                {
                    dataDean.AuditingFlg = 1;
                    if (string.IsNullOrEmpty(dataDean.AuditingId))
                    {
                        ((Design_MasterPage)this.Master).InfoMessage =
                            HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0100").ToString().Replace("{0}", "审核人");
                        return;
                    }
                }
                else
                {
                    dataDean.AuditingFlg = 0;
                    dataDean.AuditingId = "";
                    dataDean.AuditingMemo = "";
                }
                
                list.Add(dataDean);
            }
            strFlg = "1";
        }
        dao.AddLodging(strFlg,list);
        //提示成功
        Response.Write("<script language=JavaScript>" +
                 "alert('" + HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0037").ToString().Replace("{0}", "登记") + "');</script>");

    }

    // 登记按钮
    protected void btnOk_Click(object sender, EventArgs e)
    {
        try
        {
            // check is allow update
            if (!ComValidator1.DoValidator())
            {
                ((Design_MasterPage)this.Master).InfoMessage = ComValidator1.ErrorMessage;
                return;
            }

            SaleProcessDao dao = new SaleProcessDao();
            SysUserManager manager = new SysUserManager(Context);
            SysUserBean sysUserBean = manager.getSysUserBean();
            MstSysUserBean mstSysUserBean =
                sysUserBean == null ? null : sysUserBean.getMstSysUserBean();
            MstEmployeeBean mstEmpBean =
                sysUserBean == null ? null : sysUserBean.getEmployeeBean();
            string loginId = mstSysUserBean == null ? "" : mstSysUserBean.SysUserId;
            string emplyId = mstSysUserBean == null ? "" : mstSysUserBean.EmployeeId;
            string emplyRole = mstEmpBean == null ? "" : mstEmpBean.Role;

            // 权限check
            if (!checkAuthority(this.ViewState["PROC_ID"].ToString(), emplyId, emplyRole))
            {
                ((Design_MasterPage)this.Master).InfoMessage =
                    HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0901").ToString();
                return;
            }

            // todo check auth
            if (!SaleProcessDao.ROLE_MANAGER.Equals(emplyRole))
            {
                ((Design_MasterPage)this.Master).InfoMessage =
                    HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0901").ToString();
                return;
            }

            // find current process
            SaleProcessBean beanSP = new SaleProcessBean();
            beanSP.SaleProcId = Convert.ToInt32(this.ViewState["PROC_ID"].ToString());
            beanSP = dao.FindBySaleProcess(beanSP);
            if (beanSP == null)
            {
                ((Design_MasterPage)this.Master).InfoMessage =
                    HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0005").ToString();
                return;
            }

            // 判断是否已经入会登记
            if (beanSP.PersonId == null)
            {
                ((Design_MasterPage)this.Master).InfoMessage =
                    HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0902").ToString().Replace("{0}", "人员登记");
                return;
            }
/*
            // 判断是否已经体检报告
            if (beanSP.PhysicalId == null)
            {
                ((Design_MasterPage)this.Master).InfoMessage =
                    HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0902").ToString().Replace("{0}", "体检报告");
                return;
            }
            if (beanSP.SecondaryPersonId != null && beanSP.SecondaryPhysicalId == null)
            {
                ((Design_MasterPage)this.Master).InfoMessage =
                    HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0902").ToString().Replace("{0}", "体检报告");
                return;
            }
            if (beanSP.AccompanyPersonId != null && beanSP.AccompanyPhysicalId == null)
            {
                ((Design_MasterPage)this.Master).InfoMessage =
                    HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0902").ToString().Replace("{0}", "体检报告");
                return;
            }

            // 判断是否已经提交审核
            if (beanSP.AuditingFlg == null
                || (beanSP.AuditingFlg != null && !beanSP.AuditingFlg.Value))
            {
                ((Design_MasterPage)this.Master).InfoMessage =
                    HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0902").ToString().Replace("{0}", "提交审核");
                return;
            }

            // 判断是否允许撤销审核（合同完成后 不允许）
            //if (!ckbPass.Checked)
            //{
            //    beanSP.ContractId;
            //}
*/
            // 更新
            beanSP.CancelFlg = ckbPass.Checked;
            beanSP.AuditingId = emplyId;
            beanSP.Auditing = txtOpinion.Text;
            if (ckbPass.Checked) beanSP.AuditingDate = DateTime.Now;
            else
            { 
                beanSP.AuditingDate = null;
                beanSP.AuditingId = null;
                beanSP.Auditing = null;
            }
            
            beanSP.UserId = loginId;
            log.Info("***** Start UPDATE *****");
            dao.Update(beanSP);
            bindSelectData(Convert.ToString(beanSP.SaleProcId));
            //SalesProcNavigate(beanSP);
            ((Design_MasterPage)this.Master).InfoMessage =
                HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0002").ToString();

        }
        catch (Exception ex)
        {
            log.Fatal(ex.StackTrace);
            log.Fatal(ex.Message);
            throw ex;
        }
    }

    //protected void SalesProcNavigate(SaleProcessBean paramBean)
    //{
    //    lnkBtn1.Enabled = false;
    //    //lnkBtn2.Enabled = false;
    //    lnkBtn3.Enabled = false;
    //    lnkBtn4.Enabled = false;
    //    lnkBtn5.Enabled = false;
    //    lnkBtn6.Enabled = false;
    //    //lnkBtn7.Enabled = false;
    //    if (paramBean != null)
    //    {
    //        for (int i = 0; i <= Convert.ToInt32(paramBean.CurrentStep.Value); i++)
    //        {
    //            if ((i + 1) < 8)
    //                ((LinkButton)this.Master.FindControl("ContentPlaceHolder1").FindControl("lnkBtn" + (i + 1).ToString())).Enabled = true;
    //        }
    //    }
    //}

    // link 按钮 click
    protected void lnkBtn_Command(object sender, CommandEventArgs e)
    {
        string directUrl = "~/App/Search/SaleProcSrhForm.aspx";
        switch (e.CommandName)
        {
            case "btn0":
                // 销售开始                
                directUrl = "~/App/Input/SaleProcessBeginForm.aspx";
                break;
            case "btn1":
                // 入会登记
                directUrl = "~/App/Input/SaleProcesseMembershipForm.aspx";
                break;
            case "btn2":
                // 体检报告
                directUrl = "~/App/Input/SaleProcessHealthForm.aspx";
                break;
            case "btn3":
                // 资格审核
                directUrl = "~/App/Input/SaleProcessIndefinForm.aspx";
                break;
            case "btn4":
                // 合同签订
                directUrl = "~/App/Input/SaleContractForm.aspx";
                break;
            case "btn5":
                // 费用缴纳
                directUrl = "~/App/Input/PaymentUpdForm.aspx";
                break;
            case "btn6":
                // 礼品发放
                directUrl = "~/App/Search/SaleProcSrhForm.aspx";
                break;
            case "btn7":
                // 完成
                directUrl = "~/App/Search/SaleProcSrhForm.aspx";
                break;
            default:
                break;
        }
        if (!string.IsNullOrEmpty(Convert.ToString(this.ViewState["PROC_ID"])))
        {
            Context.Items["SALE_PROC_ID"] = this.ViewState["PROC_ID"];
        }
        ControllerUtils.Transfer(Context, directUrl, true);

    }

    // 是否有更新权限 check
    private Boolean checkAuthority(string procId, string emplyId, string role)
    {
        SaleProcessDao daoCheck = new SaleProcessDao();
        SaleProcessBean bean = new SaleProcessBean();
        bean.SaleProcId = Convert.ToInt32(procId);
        bean.EmployeeId = emplyId;
        bean.Role = role;
        IList list = daoCheck.CheckSaleProcessAu(bean);
        if (list == null || list.Count == 0) return false;
        return true;
    }

    // bind select data by procId
    private Boolean bindSelectData(string procId)
    {
        SaleProcessDao dao = new SaleProcessDao();
        SaleProcessBean beanSP = new SaleProcessBean();

        beanSP.SaleProcId = Convert.ToInt32(procId);
        beanSP = dao.FindBySaleProcess(beanSP);
        if (beanSP == null) return false;

        lblProcId.Text = Convert.ToString(beanSP.SaleProcId);
        lblEmpId.Text = string.Format("{0} {1}", beanSP.EmployeeId, beanSP.EmployeeName);
        Label1.Text = Convert.ToString(beanSP.PersonId);
        Label2.Text = Convert.ToString(beanSP.SecondaryPersonId);
        Label3.Text = Convert.ToString(beanSP.AccompanyPersonId);
        lblPersonMain.Text = beanSP.PersonNameMain;//string.Format("{0} {1}", Convert.ToString(beanSP.PersonId), Convert.ToString(beanSP.PersonNameMain));
        lblPersonAsst.Text = beanSP.PersonNameAsst;//string.Format("{0} {1}", Convert.ToString(beanSP.SecondaryPersonId), Convert.ToString(beanSP.PersonNameAsst));
        lblPersonComp.Text = beanSP.PersonNameComp;//string.Format("{0} {1}", Convert.ToString(beanSP.AccompanyPersonId), Convert.ToString(beanSP.PersonNameComp));

        lblPhysicalIdMain.Text = Convert.ToString(beanSP.PhysicalId);
        lblPhysicalIdAsst.Text = Convert.ToString(beanSP.SecondaryPhysicalId);
        lblPhysicalIdComp.Text = Convert.ToString(beanSP.AccompanyPhysicalId);
        lblPhysicalIdMain.Visible = false;
        lblPhysicalIdAsst.Visible = false;
        lblPhysicalIdComp.Visible = false;
        btnPsnDtl1.Enabled = !string.IsNullOrEmpty(Label1.Text);
        btnRptDtl1.Enabled = !string.IsNullOrEmpty(lblPhysicalIdMain.Text);
        btnPsnDtl2.Enabled = !string.IsNullOrEmpty(Label2.Text);
        btnRptDtl2.Enabled = !string.IsNullOrEmpty(lblPhysicalIdAsst.Text);
        btnPsnDtl3.Enabled = !string.IsNullOrEmpty(Label3.Text);
        btnRptDtl3.Enabled = !string.IsNullOrEmpty(lblPhysicalIdComp.Text);

        lblCurUser.Text = beanSP.AuditingId;
        txtOpinion.Text = beanSP.Auditing;

        //txtAuditingDate.ReadOnly = true;
        if (beanSP.AuditingDate != null)
            txtAuditingDate.Text = DateUtils.convertToString(beanSP.AuditingDate.Value);
        else if (!beanSP.CancelFlg)
            txtAuditingDate.Text = DateUtils.convertToString(DateTime.Now);
        ckbPass.Checked = beanSP.CancelFlg;

        this.ViewState["CANCEL_FLG"] = beanSP.CancelFlg;
        //this.ViewState["CUR_STEP"] = beanSP.CurrentStep;
        if (beanSP.CancelFlg) return false;

        return true;
    }

    // set link button status
    //private void setLinkStatus()
    //{
    //    // page is allow edit
    //    //if (this.ViewState["PROC_ID"] == null            
    //    //    || this.ViewState["CUR_STEP"] == null
    //    //    || this.ViewState["CANCEL_FLG"] == null            
    //    //    || (Boolean)this.ViewState["CANCEL_FLG"])
    //    //{
    //    //    btnOk.Enabled = false;
    //    //    ((Design_MasterPage)this.Master).InfoMessage =
    //    //        HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0005").ToString();
    //    //}

    //    //if (string.IsNullOrEmpty(Convert.ToString(this.ViewState["CUR_STEP"]))
    //    //    || Convert.ToInt32(this.ViewState["CUR_STEP"]) >= SaleProcessDao.SALE_PROCESS_STEP_4)
    //    //{
    //    //    ((Design_MasterPage)this.Master).InfoMessage =
    //    //        HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0004").ToString();
    //    //    btnOk.Enabled = false;
    //    //}

    //    //// 判断是否已经体检报告
    //    //if (Convert.ToInt32(this.ViewState["CUR_STEP"]) < SaleProcessDao.SALE_PROCESS_STEP_2
    //    //    || lblPersonMain.Text == string.Empty
    //    //    || lblPhysicalIdMain.Text == string.Empty)
    //    //{
    //    //    ((Design_MasterPage)this.Master).InfoMessage =
    //    //        HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0902").ToString().Replace("{0}", "体检报告");
    //    //    btnOk.Enabled = false;
    //    //}

    //    // 流程跟踪 link button
    //    if (this.ViewState["CUR_STEP"] != null)
    //    {
    //        for (int i = 0; i <= Convert.ToInt32(this.ViewState["CUR_STEP"]); i++)
    //        {
    //            if ((i + 1) < 8)
    //                ((LinkButton)this.Master.FindControl("ContentPlaceHolder1").FindControl("lnkBtn" + (i + 1).ToString())).Enabled = true;
    //        }
    //    }
    //}

    // bind db data to selected controls
    private void bindDataToListControl(string ControlId, IList LstData)
    {
        if (LstData == null || LstData.Count == 0) return;

        foreach (CommonDictionaryBean bean in LstData)
        {
            if (this.Master.FindControl("ContentPlaceHolder1").FindControl(ControlId) is DropDownList)
            {
                ((DropDownList)this.Master.FindControl("ContentPlaceHolder1").FindControl(ControlId)).Items.Add(new ListItem(bean.Content, bean.DictNo.ToString()));
            }
            else if ((this.Master.FindControl("ContentPlaceHolder1").FindControl(ControlId) is CheckBoxList)
                || (this.Master.FindControl("ContentPlaceHolder1").FindControl(ControlId) is RadioButtonList))
            {
                ((ListControl)this.Master.FindControl("ContentPlaceHolder1").FindControl(ControlId)).Items.Add(new ListItem(bean.Content, bean.DictNo.ToString()));
            }
        }
    }

    // tab go
    protected void lnkTab_Command(object sender, CommandEventArgs e)
    {

        string directUrl = "~/App/Input/MemberForm.aspx";
        switch (e.CommandName)
        {
            case "btn0":
                // 新建洽谈
                directUrl = "~/App/Input/SaleProcessBeginForm.aspx";
                break;
            case "btn1":
                // 销售管理
                directUrl = "~/App/Input/SaleCountForm.aspx";
                break;
            case "btn2":
                // 入住管理
                directUrl = "~/App/Input/MemberForm.aspx";
                break;
            case "btn3":
                // 购卡管理
                directUrl = "~/App/Input/RightPersonForm.aspx";
                break;
            case "btn4":
                // 客户移交                
                directUrl = "~/App/Input/ContractHabitationForm.aspx";
                break;
            case "btn2_1":
                // 主会员信息
                directUrl = "~/App/Input/MemberForm.aspx";
                break;
            case "btn2_2":
                // 副会员信息
                directUrl = "~/App/Input/ViceMemberForm.aspx";
                break;
            case "btn2_3":
                // 陪住人信息
                directUrl = "~/App/Input/AccompanyForm.aspx";
                break;
            case "btn2_4":
                // 体检报告
                directUrl = "~/App/Input/SaleProcessHealthForm.aspx";
                break;
            case "btn2_5":
                // 审核
                directUrl = "~/App/Input/SaleProcessIndefinForm.aspx";
                break;
            case "btn2_6":
                // 入住合同
                directUrl = "~/App/Input/ContractHabitationForm.aspx";
                break;
            case "btn2_7":
                // 特点
                directUrl = "~/App/Input/PersonTraitUpdForm.aspx";
                break;
            default:
                break;
        }
        if (!string.IsNullOrEmpty(Convert.ToString(this.ViewState["PROC_ID"])))
        {
            Context.Items["SALE_PROC_ID"] = this.ViewState["PROC_ID"];
        }
        ControllerUtils.Transfer(this.Context, directUrl, false);
    }

    protected void memberRadio_SelectedIndexChanged(object sender, EventArgs e)
    {
        
        SaleProcessDao dao = new SaleProcessDao();

                SaleProcessBean beanSP = new SaleProcessBean();

                beanSP.SaleProcId = Convert.ToInt32(this.ViewState["PROC_ID"]);
                beanSP = dao.FindBySaleProcess(beanSP);
                if (memberRadio.SelectedValue=="0")
                {
                    Context.Items["PERSON_ID"] = Convert.ToString(beanSP.PersonId);
                }
                else if (memberRadio.SelectedValue == "1")
                {
                    Context.Items["PERSON_ID"] = Convert.ToString(beanSP.SecondaryPersonId);
                }
                else
                {
                    Context.Items["PERSON_ID"] = Convert.ToString(beanSP.AccompanyPersonId);
                }
                Context.Items["SALE_PROC_ID"] = Convert.ToString(this.ViewState["PROC_ID"]);
                Context.Items["MAIN_PERSON_ID"] = Convert.ToString(this.ViewState["MAIN_PERSON_ID"]);
                string directUrl = "~/App/Input/SaleProcessIndefinForm.aspx";
                while (TblSale.Rows.Count > 1)
                {
                    TblSale.Rows.RemoveAt(1);
                }
                ControllerUtils.Transfer(this.Context, directUrl, false);
    }

}
